#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>

int main()
{
	pid_t id = fork();
	if (id == 0) {	// child process
		int count = 5;
		while (count) {
			printf("I am child process.....PID:%d, PPID:%d, count:%d\n", getpid(), getppid(), count);
			sleep(1);
            count--;
		}
        printf("child process quit\n");
		exit(0);
	}

    // father process
	int status = 0;
	pid_t ret = wait(&status);
	if (ret > 0) {
		// wait success
		printf("wait child process success\n");
		if (WIFEXITED(status)) {
			// exit normal
			printf("child process exit code:%d\n", WEXITSTATUS(status));
		}
	}
	sleep(3);
    printf("father process quit\n");
	return 0;
}